import { getToken } from "@/utils/token";
import Vue from "vue";
import VueRouter from "vue-router";
//引入组件
Vue.use(VueRouter);

/* 引入最外层骨架的一级路由组件 */
const routes = [{
    path: "/",
    name: "layout",
    component: () => import("@/layout/index.vue"),
    // redirect: '/record',
    redirect: () => {
        return getToken("rname") == '管理员' ? '/record' : '/teaEndRecord'
    },
    children: [
        { path: '/record', component: () => import('@/views/record/index') },//数据分析
        { path: '/teaEndRecord', component: () => import('@/views/teaEndRecord/index') },//招聘数据分析
        { path: '/user', component: () => import('@/views/user/index.vue') },//用户管理
        { path: '/position', component: () => import('@/views/position/index.vue') },//职位管理
        { path: '/positionAdd', component: () => import('@/views/position/add.vue') },//添加职位信息
        { path: '/positions', component: () => import('@/views/position/audit.vue') },//职位详情
        { path: '/review', component: () => import('@/views/review/index.vue') },//职位审核
        { path: '/enterprise', component: () => import('@/views/enterprise/index.vue') },//企业管理
        { path: '/auditAdd', component: () => import('@/views/enterprise/examine.vue') },//企业审核详情
        { path: '/addEnterprises', component: () => import('@/views/enterprise/addEnterprises.vue') },//企业审核详情
        { path: '/notes', component: () => import('@/views/notes/index.vue') },//简历管理
        { path: '/review', component: () => import('@/views/review/index.vue') },//职位审核
        { path: '/Business', component: () => import('@/views/enterprise/Business.vue') },//我的企业

    ]
},
//登录
{
    path: "/login",
    name: "login",
    component: () => import("@/views/login/index.vue")
}
];

// 创建并暴露一个路由器
const router = new VueRouter({
    routes,
});

router.beforeEach((to, from, next) => {
    if (to.path != '/login') {
        if (getToken("token")) {
            next()
        } else {
            next('/login')
        }
    } else {
        next()
    }
})

export default router;

